/*
*   FourierTransformExample
*
*   This class demonstrates a use of the FourierTransform class
*   A 256 point wave form formed by adding two sine waves
*       y = sin(2.pi.t) + 2sin(10.pi.t);
*   is first plotted, then its power spectrum is obtained
*   and displayed.  The transformed data is then put
*   through a inverse Fourier transform and the inverse
*   transformed data, which should be the same as the
*   original wave form, is then displayed.
*
*   AUTHOR: Dr Michael Thomas Flanagan
*   DATE:   24 January 2006
*
*   Copyright (c) January 2006  Michael Thomas Flanagan
*
*   PERMISSION TO COPY:
*   Permission to use, copy and modify this software and its documentation for
*   NON-COMMERCIAL purposes is granted, without fee, provided that an acknowledgement
*   to the author, Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies.
*
*   Dr Michael Thomas Flanagan makes no representations about the suitability
*   or fitness of the software for any or for a particular purpose.
*   Michael Thomas Flanagan shall not be liable for any damages suffered
*   as a result of using, modifying or distributing this software or its derivatives.
*
***************************************************************************************/

import flanagan.io.*;
import flanagan.math.*;
import flanagan.plot.*;

public class test{

    public static void main(String[] args){



        double[] tdata = new double[ydata.length];
        int nPoints = tdata.length;  // number of points.

        double amplitude1 = 1.0D;
        double amplitude2 = 2.0D;
        double pointsPerCycle = 5;
        double deltaT = 0.17D;

        // Create wave form
        for(int i=0; i<nPoints; i++){
            //ydata[i]= amplitude1*Math.sin(2.0D*Math.PI*i/pointsPerCycle)+ amplitude2*Math.sin(10.0D*Math.PI*i/pointsPerCycle);
            tdata[i]=i*deltaT;
        }

        /*for(int i=0; i<1024; i++){
           // ydata[i]= amplitude1*Math.sin(2.0D*Math.PI*i/pointsPerCycle)+ amplitude2*Math.sin(10.0D*Math.PI*i/pointsPerCycle);
            tdata[i]=i*deltaT;
        }*/
        // Plot original data
        PlotGraph pg0 = new PlotGraph(tdata, ydata);
        pg0.setGraphTitle("y = sin(2.pi.t) + 2sin(10.pi.t)");
        pg0.setXaxisLegend("time");
        pg0.setXaxisUnitsName("s");
        pg0.setXaxisLegend("y");
        pg0.plot();

        // Obtain Power spectrum

        FFTCustom ft0 = new FFTCustom(ydata);
        ft0.setDeltaT(deltaT);
        ft0.setWelch();
//        ft0.setHamming();
        ft0.setSegmentNumber(8);
        //ft0.setSegmentLength(31);
        //ft0.setOverlapOption(true);
        ft0.plotPowerSpectrum();

        //double[][] powerSpectrum = ft0.powerSpectrum();
       /* System.out.println("freq\tampli");
        for (int i = 0; i < powerSpectrum[0].length; i++) {
        	System.out.println(powerSpectrum[0][i]+"\t"+powerSpectrum[1][i]);
		}*/
        /*PlotGraph pg1 = new PlotGraph(powerSpectrum[0], powerSpectrum[1]);
        pg1.setGraphTitle("Test");
        pg1.plot();*/
        /*System.out.println(ft0.getWindowOption());
        System.out.println("getSegmentNumber "+ft0.getSegmentNumber());
        System.out.println("getSegmentLength "+ft0.getSegmentLength());
        System.out.println("getOverLapOption "+ft0.getOverlapOption());*/

        // Plot power spectrum
//        ft0.printPowerSpectrum();
//
//
//
//
//        ft0.setPlotLineOption(2);
//        ft0.setSegmentNumber(3);
//        ft0.setOverlapOption(true);





    }

    static double[] ydata = {-0.05247,
    	0.09880,
    	-0.02059,
    	0.07008,
    	0.07748,
    	0.04135,
    	0.09666,
    	0.02339,
    	0.03768,
    	0.13342,
    	0.01450,
    	0.17562,
    	0.00741,
    	0.15398,
    	-0.03639,
    	0.02011,
    	0.02485,
    	-0.04460,
    	0.09648,
    	0.01670,
    	0.03783,
    	0.01360,
    	-0.03487,
    	0.06676,
    	-0.02001,
    	0.12262,
    	-0.04855,
    	-0.02808,
    	-0.01601,
    	-0.14545,
    	-0.01105,
    	-0.07755,
    	-0.07254,
    	0.02782,
    	-0.04712,
    	0.07204,
    	-0.03653,
    	0.03283,
    	-0.00696,
    	-0.00009,
    	0.04703,
    	-0.03816,
    	-0.00302,
    	0.05606,
    	-0.01980,
    	0.16868,
    	-0.02181,
    	0.07538,
    	-0.02256,
    	-0.03021,
    	0.06532,
    	-0.05477,
    	-0.00718,
    	-0.00055,
    	-0.05744,
    	0.08414,
    	-0.02862,
    	0.11104,
    	-0.05670,
    	0.02793,
    	-0.00057,
    	-0.02546,
    	0.05914,
    	-0.03440,
    	-0.02607,
    	0.01597,
    	-0.04518,
    	0.11669,
    	0.00212,
    	0.09130,
    	-0.01770,
    	0.00736,
    	0.02674,
    	-0.05000,
    	0.01268,
    	0.01562,
    	-0.00547,
    	0.07914,
    	0.00230,
    	0.06583,
    	0.08821,
    	-0.00801,
    	0.11530,
    	-0.05172,
    	-0.01538,
    	-0.00441,
    	-0.05668,
    	0.06768,
    	-0.03710,
    	0.13245,
    	-0.03125,
    	0.11887,
    	-0.05178,
    	0.03216,
    	0.02819,
    	-0.00906,
    	0.12504,
    	0.01017,
    	0.03767,
    	0.00608,
    	-0.03807,
    	0.02978,
    	-0.01942,
    	0.08927,
    	-0.00495,
    	0.04694,
    	0.05299,
    	-0.02546,
    	0.10060,
    	-0.00649,
    	0.01270,
    	0.08228,
    	-0.03745,
    	0.09826,
    	0.00854,
    	0.02824,
    	-0.03883,
    	-0.01282,
    	0.00470,
    	-0.02546,
    	0.08356,
    	0.02287,
    	0.00709,
    	0.11010,
    	-0.02611,
    	0.14265,
    	-0.00705,
    	0.07236,
    	-0.05380,
    	-0.02317,
    	-0.05090,
    	-0.04055,
    	0.02348,
    	0.00678,
    	0.00172,
    	0.06267,
    	-0.03230,
    	0.07689,
    	-0.03847,
    	0.03538,
    	-0.08974,
    	-0.00176,
    	-0.02759,
    	-0.01297,
    	0.07407,
    	0.01605,
    	0.02391,
    	0.06088,
    	-0.01602,
    	0.04775,
    	-0.02201,
    	0.03332,
    	-0.05924,
    	0.03654,
    	0.01469,
    	-0.00110,
    	0.06738,
    	-0.06553,
    	-0.04983,
    	-0.01375,
    	-0.08697,
    	0.07093,
    	-0.03394,
    	-0.01976,
    	-0.04941,
    	-0.03672,
    	-0.06230,
    	-0.05704,
    	-0.00198,
    	-0.08356,
    	0.05834,
    	-0.01818,
    	-0.00835,
    	-0.00197,
    	-0.03467,
    	0.00568,
    	-0.04942,
    	0.01083,
    	-0.06795,
    	-0.06317,
    	0.03907,
    	-0.08333,
    	0.14609,
    	-0.02916,
    	0.05353,
    	0.03924,
    	-0.03326,
    	0.10920,
    	-0.04457,
    	0.12335,
    	0.04900,
    	0.03029,
    	0.12415,
    	-0.09137,
    	0.08512,
    	-0.06456,
    	0.02841,
    	0.03551,
    	-0.02831,
    	0.08084,
    	-0.04459,
    	0.08843,
    	-0.02941,
    	-0.00587,
    	0.01233,
    	-0.07889,
    	-0.00314,
    	-0.02114,
    	-0.03459,
    	0.03596,
    	-0.01171,
    	0.08895,
    	0.01257,
    	0.04378,
    	-0.04591,
    	-0.01471,
    	-0.02519,
    	-0.05331,
    	0.01950,
    	-0.09192,
    	-0.01734,
    	-0.06405,
    	-0.02892,
    	0.00650,
    	-0.04051,
    	0.01163,
    	-0.04268,
    	0.02409,
    	-0.07161,
    	0.00085,
    	-0.00931,
    	-0.05763,
    	0.05426,
    	-0.05616,
    	0.03452,
    	-0.01170,
    	-0.00287,
    	0.00762,
    	-0.04358,
    	0.03525,
    	-0.04128,
    	0.03928,
    	-0.02859,
    	0.02174,
    	0.03051,
    	-0.00054,
    	0.08961,
    	-0.02283,
    	0.01311,
    	0.04345,
    	-0.04992,
    	0.06236,
    	-0.10023,
    	0.03914,
    	-0.07453,
    	-0.01498,
    	-0.01334,
    	-0.06910,
    	-0.03759,
    	0.02198,
    	-0.02730,
    	0.11306,
    	-0.01701,
    	0.08327,
    	-0.08130,
    	-0.02692,
    	-0.04596,
    	-0.07781,
    	0.04039,
    	-0.02398,
    	-0.04826,
    	0.03724,
    	-0.08864,
    	0.09845,
    	-0.03646,
    	0.08523,
    	-0.03117,
    	0.05114,
    	0.00411,
    	0.04531,
    	0.03939,
    	0.03948,
    	-0.04977,
    	0.05151,
    	-0.08496,
    	0.01685,
    	-0.03875,
    	0.08335,
    	-0.01561,
    	0.02746,
    	0.03662,
    	-0.08270,
    	0.06595,
    	-0.07036,
    	0.00442,
    	0.01643,
    	-0.05712,
    	0.08080,
    	-0.02977,
    	0.02530,
    	-0.00036,
    	-0.03033,
    	0.01598,
    	-0.03718,
    	-0.08118,
    	0.01865,
    	-0.11451,
    	0.07403,
    	-0.05096,
    	0.05021,
    	-0.09941,
    	0.03051,
    	-0.08349,
    	-0.01553,
    	0.01064,
    	-0.06158,
    	-0.03856,
    	0.00069,
    	-0.03887,
    	0.06295,
    	-0.00517,
    	0.03223,
    	-0.07753,
    	-0.05164,
    	-0.05291,
    	-0.08779,
    	0.01360,
    	-0.05659,
    	-0.06684,
    	-0.07139,
    	-0.15151,
    	-0.07336,
    	-0.10921,
    	-0.05524,
    	-0.06692,
    	0.04900,
    	-0.02835,
    	0.15120,
    	-0.04213,
    	0.08012,
    	-0.06626,
    	0.00904,
    	-0.06974,
    	0.02119,
    	-0.05012,
    	0.01706,
    	-0.03051,
    	0.01292,
    	0.02686,
    	0.02728,
    	0.05599,
    	0.02382,
    	0.06251,
    	-0.01541,
    	0.06903,
    	-0.05465,
    	-0.01270,
    	-0.01775,
    	-0.02693,
    	0.11043,
    	0.02841,
    	0.13085,
    	-0.04583,
    	0.06872,
    	0.01664,
    	0.04319,
    	0.06641,
    	0.01766,
    	-0.00556,
    	-0.02444,
    	-0.04196,
    	-0.00061,
    	-0.04135,
    	0.05966,
    	-0.00859,
    	0.12865,
    	-0.00314,
    	0.03826,
    	0.01622,
    	-0.06405,
    	0.03557,
    	-0.07144,
    	-0.02427,
    	-0.02474,
    	-0.01765,
    	0.11520,
    	0.00120,
    	0.11062,
    	-0.02028,
    	-0.01380,
    	-0.02776,
    	-0.06240,
    	-0.03524,
    	-0.07582,
    	-0.05812,
    	0.00363,
    	-0.00645,
    	0.08621,
    	-0.02634,
    	0.00902,
    	-0.04335,
    	-0.01539,
    	-0.05829,
    	-0.05065,
    	-0.00321,
    	-0.06945,
    	-0.01831,
    	-0.02951,
    	-0.08122,
    	0.04436,
    	-0.01456,
    	0.05245,
    	-0.02669,
    	-0.04015,
    	-0.00843,
    	-0.06328,
    	0.04516,
    	-0.02743,
    	0.04404,
    	-0.03801,
    	-0.01075,
    	-0.00843,
    	-0.04777,
    	0.04899,
    	-0.03802,
    	0.08614,
    	-0.01226,
    	0.02670,
    	0.05717,
    	-0.04045,
    	0.14598,
    	-0.01402,
    	0.07919,
    	0.04095,
    	-0.02383,
    	0.09626,
    	-0.01709,
    	0.12925,
    	-0.01714,
    	0.05539,
    	0.04592,
    	-0.05439,
    	-0.03997,
    	-0.01870,
    	-0.11458,
    	0.04622,
    	-0.04134,
    	0.01354,
    	-0.02956,
    	-0.04441,
    	0.00275,
    	-0.04485,
    	0.03506,
    	-0.04529,
    	-0.02716,
    	0.03073,
    	-0.04197,
    	0.08162,
    	-0.02154,
    	0.09434,
    	-0.09224,
    	-0.00887,
    	-0.02388,
    	-0.09806,
    	0.10166,
    	-0.04260,
    	0.03900,
    	0.03422,
    	-0.01813,
    	0.11176,
    	-0.02469,
    	0.07240,
    	-0.09122,
    	-0.06370,
    	-0.03714,
    	-0.09644,
    	0.05339,
    	-0.04953,
    	0.04187,
    	0.01344,
    	0.03438,
    	0.07640,
    	0.02689,
    	0.09363,
    	-0.04292,
    	0.01515,
    	-0.02107,
    	-0.04198,
    	0.01332,
    	-0.05875,
    	-0.00928,
    	0.01209,
    	-0.00891,
    	0.13117,
    	-0.00855,
    	0.07902,
    	-0.01472,
    	0.01003,
    	0.00101,
    	0.00564,
    	0.01673,
    	0.00125,
    	-0.01207,
    	0.07729,
    	-0.01997,
    	0.09474,
    	-0.01360,
    	0.06789,
    	-0.01406,
    	-0.00761,
    	0.03730,
    	-0.06232,
    	-0.02417,
    	0.00992,
    	-0.06065,
    	0.06128,
    	-0.02824,
    	0.05241,
    	-0.06330,
    	-0.03876,
    	-0.01593,
    	-0.06377,
    	0.02936,
    	-0.06639,
    	0.00520,
    	-0.04149,
    	0.00418,
    	0.06248,
    	0.00315,
    	0.05251,
    	-0.01709,
    	0.02469,
    	-0.05108,
    	0.02515,
    	-0.02035,
    	-0.02420,
    	0.01038,
    	-0.07355,
    	-0.03958,
    	-0.03250,
    	-0.02556,
    	0.04736,
    	-0.01155,
    	0.06179,
    	0.00417,
    	0.02411,
    	-0.03314,
    	-0.07679,
    	-0.07046,
    	-0.09213,
    	0.03319,
    	-0.04892,
    	-0.03608,
    	0.00406,
    	-0.06775,
    	0.04704,
    	-0.01507,
    	-0.02113,
    	-0.00619,
    	-0.07114,
    	0.03793,
    	-0.07720,
    	-0.01323,
    	-0.01898,
    	-0.06711,
    	0.06501,
    	-0.04204,
    	0.02116,
    	-0.05844,
    	-0.02770,
    	-0.03228,
    	-0.03997,
    	-0.00612,
    	-0.05225,
    	-0.08294,
    	-0.01040,
    	-0.08355,
    	0.03144,
    	-0.04536,
    	0.02609,
    	-0.08996,
    	0.04202,
    	-0.03126,
    	0.00256,
    	0.04854,
    	-0.03691,
    	-0.00779,
    	0.01283,
    	-0.03607,
    	0.06449,
    	-0.03621,
    	0.12529,
    	-0.03239,
    	0.04640,
    	0.00062,
    	-0.06609,
    	-0.00048,
    	-0.02871,
    	-0.00855,
    	0.05937,
    	-0.00539,
    	0.07732,
    	-0.03188,
    	0.05299,
    	-0.02032,
    	-0.00186,
    	0.03387,
    	-0.05724,
    	0.03227,
    	-0.03356,
    	0.00306,
    	0.02133,
    	-0.00668,
    	0.10674,
    	-0.03609,
    	0.12511,
    	-0.02914,
    	-0.00948,
    	0.04050,
    	-0.07064,
    	0.14000,
    	-0.00899,
    	0.06888,
    	0.04269,
    	-0.03687,
    	0.07244,
    	-0.01704,
    	0.02693,
    	-0.02170,
    	0.00693,
    	0.00795,
    	0.01912,
    	0.03759,
    	0.03131,
    	-0.04271,
    	0.05696,
    	-0.03583,
    	0.08635,
    	-0.00434,
    	0.06178,
    	-0.03253,
    	-0.06134,
    	0.03776,
    	-0.08043,
    	0.10805,
    	-0.00877,
    	0.01942,
    	0.05606,
    	-0.04882,
    	0.09619,
    	-0.02991,
    	0.05666,
    	-0.04887,
    	0.02101,
    	0.01247,
    	0.01217,
    	0.07381,
    	0.00333,
    	0.02534,
    	0.04093,
    	-0.07156,
    	0.06402,
    	-0.07658,
    	-0.04132,
    	-0.03484,
    	-0.12015,
    	0.00803,
    	-0.08866,
    	-0.06725,
    	-0.02012,
    	-0.08066,
    	0.06389,
    	-0.05054,
    	0.07440,
    	-0.06422,
    	-0.04095,
    	-0.03089,
    	-0.10952,
    	0.00244,
    	-0.03823,
    	-0.05020,
    	0.01203,
    	-0.09545,
    	0.01576,
    	-0.08433,
    	0.00151,
    	-0.03509,
    	-0.05872,
    	0.02527,
    	-0.09811,
    	0.05238,
    	-0.03904,
    	-0.00424,
    	0.04023,
    	-0.06180,
    	0.07495,
    	-0.06453,
    	0.00857,
    	-0.03696,
    	-0.07196,
    	-0.00432,
    	-0.08951,
    	-0.06844,
    	-0.08788,
    	-0.12958};
}
